package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import org.redisson.client.ChannelName;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Configuration
public class DeadLetterReceiver {

    @RabbitListener(queues = DeadLetterMqConfig.queue_dead_2)
    @SneakyThrows
    public void deadLetter(String msg, Message message, Channel channel){

        System.out.println("消息内容：\t"+msg);
        //创建时间格式化类
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        //显示时间
        System.out.println("消息接收时间：\t"+simpleDateFormat.format(new Date()));

        //确认消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }
}
